package 链表.单向.练习;
//回文列表
import java.util.*;

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class Text_6 {
    public boolean chkPalindrome(ListNode head) {
        // 找中间节点
        ListNode slow = head;
        ListNode fast = head;
        while(fast!=null&&fast.next!=null){
            fast = fast.next.next;
            slow = slow.next;
        }
//        反转中间节点后的列表
        ListNode cur = slow.next;
        ListNode curNext;
        while(cur!=null){
            curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }
        //进行比较
        while(head!=slow){
            if(head.val != slow.val){
                return false;
            }
            //偶数回文判断
            if(head.next ==slow){
                return true;
            }
            head = head.next;
            slow = slow.next;
        }
        return true;
    }
}